import { create } from "zustand";
import { persist } from "zustand/middleware";

// 定义用户类型
type UserState = {
  token: string;
  email: string;
  real_name: string;
  role: number;
  setData: (
    token: string,
    email: string,
    real_name: string,
    role: number
  ) => void;
};

const useUserStore = create<UserState>()(
  persist(
    (set) => ({
      token: "",
      email: "",
      real_name: "",
      role: 0,
      setData: (token, email, real_name, role) =>
        set({ token: token, email: email, real_name: real_name, role: role }),
    }),
    { name: "userStore" }
  )
);

export default useUserStore;
